package top.byteio.common.message.client;

import com.aliyun.dysmsapi20180501.Client;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import top.byteio.common.message.pojo.MessagerProperty;
/**
 * 阿里云短信客户端配置
 * @author lerryxia
 */
@NoArgsConstructor
@Slf4j
public class SMSAliyunMessageHelper implements MessagerHelper<Client> {
    public Client getHelper(MessagerProperty property) {
        try {
            com.aliyun.credentials.Client credential = new com.aliyun.credentials.Client();
            com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
                    .setCredential(credential)
                    // Endpoint 请参考 https://api.aliyun.com/product/Dysmsapi
                    .setEndpoint(property.getEndpoint())
                    .setAccessKeySecret(property.getAccessKey())
                    .setAccessKeySecret(property.getSecurityKey())
                    .setRegionId(property.getRegion())
                    .setConnectTimeout(property.getTimeout());
            log.info("初始化阿里云短信客户端: endpoint={}, regionId={}",
                    property.getEndpoint(), property.getRegion());
            return new com.aliyun.dysmsapi20180501.Client(config);

        } catch (Exception e) {
            log.error("阿里云短信客户端初始化失败: {}", e.getMessage(), e);
            throw new RuntimeException("阿里云短信客户端初始化失败", e);
        }
    }
}
